<?php
namespace App\Models\Authority\Method;

use App\Models\Authority\Interfaces\AuthorityInterface;
use App\Libraries\Response\DataModel;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use App\Models\Power\User;
use Illuminate\Support\Facades\DB;
use App\Models\Base\PowerBase;

class powerUser implements AuthorityInterface
{
    public function Login(&$code, $uID)
    {
        
        $field = ['username','tel','integral','money','created_at'];
        $memberInfo = DB::connection("jmft_power") -> table("cdz_user")
                    -> where('uid',$uID) -> first($field);
         if($memberInfo){
             $memInfo = (array)$memberInfo;
             $powermodel = new PowerBase();
             $powermodel -> updateCdzUser($uID);
         }else{
             $memInfo = [];
         }
         return $memInfo;

    }
    public function Reg(&$code, $uInfo, $rqt)
    {   

        $user['uid'] = $uInfo['usersid'];
        $user['tel'] = $uInfo['phone'];
        $user['username'] = $uInfo['phone'];
        $user['password'] = $uInfo['password'];
        $user['position'] = 7;
        $user['superior'] = 1;
        $user['last_superior'] = 1;
        $user['promoter'] = 1;
        $user['created_at'] = time();

        if($rqt['keys'] == 'cdz') {
            $user['type'] = 1;
        } else {
            $user['type'] = 2;
        }
        $result = DB::connection("jmft_power") -> table("cdz_user")
        -> insertGetId($user);

        if($result) {
            $powermodel = new PowerBase();
            $powermodel -> updateCdzUser($uInfo['usersid']);
            return $user;
        } else {
            return [];
        }

    }
    public function Logout(&$code, $uID)
    {

    }
    public function Edit(&$code, $uInfo, $rqt)
    {

    }
}
